import 'package:cms/home_page.dart';
import 'package:cms/pages/categories/categories.dart';
import 'package:cms/pages/categories/detail.dart';
import 'package:cms/pages/read/native.dart';
import 'package:cms/pages/search/search.dart';
import 'package:cms/state/lara_press_cms/lara_press_cms_cubit.dart';
import 'package:common/export/get_it.dart';
import 'package:common/export/tools.dart';

/// A Calculator.
class LaraPressCms {
  /// 初始化 LaraPressCmsCubit
  static void setupLaraPressCmsCubit() {
    laraPressGetIt.registerSingleton<LaraPressCmsCubit>(LaraPressCmsCubit());
  }

  /// 注册CMS插件的路由
  static void registerRoutes(List<RouteBase> routes) {
    routes.addAll([
      GoRoute(
        path: '/cms',
        name: 'cms',
        builder: (context, state) => const LaraPressCmsHomePage(),
        routes: [
          GoRoute(
            path: '/search',
            name: 'cms-search',
            builder: (context, state) => const SearchPage(),
          ),
          GoRoute(
            path: '/categories',
            name: 'cms-categories',
            builder: (context, state) => const LaraPressCmsCategoriesPage(),
            routes: [
              GoRoute(
                path: 'detail/:id',
                name: 'cms-categories-detail',
                builder: (context, state) => LaraPressCmsCategoriesDetailPage(
                  id: int.parse(state.pathParameters['id']!),
                ),
              ),
            ],
          ),
          GoRoute(
            path: '/detail/:id',
            name: 'cms-detail',
            builder: (context, state) {
              return LaraPressCmsReadNative(
                id: int.parse(state.pathParameters['id']!),
              );
            },
          ),
        ],
      ),
    ]);
  }
}
